<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>车享乐-首页</title>
    <link rel="stylesheet" type="text/css" href="/static/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/static/css/main.css">
    <script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="/static/js/slide.js"></script>

    <script type="text/javascript" src="../../static/layui/layui.js"></script>
    <link href="../../static/layui/css/layui.css" rel="stylesheet" rel="stylesheet">
    <script src="../../static/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .avatar-img {
            width: 20px; /* 设置头像图片的宽度 */
            height: 20px; /* 设置头像图片的高度，可以根据需要调整 */
            border-radius: 50%; /* 使图片呈现圆形 */
            margin-right: 10px; /* 设置头像图片与用户名之间的间距，可以根据需要调整 */
        }
    </style>
</head>
<body>
    <div class="header_con">
        <div class="header">
            <div class="welcome fl">欢迎来到鑫鑫车享乐租车系统!  祝您畅享旅途，鑫鑫相伴！</div>
            <div class="fr">
                <div class="user_link fl">
                    <a href="javascript:;">
                        欢迎您：<img class="avatar-img" src="/pic/${user.avatar}"/>
                        ${user.username}
                    </a>
                    <span>|</span>
                    <a href="/page/user/info">用户中心</a>
                    <span>|</span>
                    <a href="/page/user/order">我的订单</a>
                    <span>|</span>
                    <a href="javascript:logout()">注销</a>
                </div>
            </div>
        </div>
    </div>

    <div class="search_bar clearfix">
        <a href="/" class="logo fl"><img src="/static/pic/xx-logo.png" width="180%"></a>
        <div class="search_con fl">
            <input type="text" id="searchInput" class="input_text fl" placeholder="搜索商品">
            <input type="button" id="searchButton" class="input_btn fr" value="搜索">
        </div>
    </div>

    <div class="navbar_con">
        <div class="navbar">
            <h1 class="fl">全部车辆品牌</h1>
            <ul class="navlist fl">
                <li><a href="/">首页</a></li>
                <li class="interval">|</li>
                <li><a href="/page/car/list">全部车辆</a></li>
            </ul>
        </div>
    </div>

    <div class="center_con clearfix">
        <ul class="subnav fl" id="LAY_BrandList">

        </ul>
        <div class="slide fl">
            <ul class="slide_pics">
                <li><img src="/static/images/slide01.png"></li>
                <li><img src="/static/images/slide02.png"></li>
                <li><img src="/static/images/slide03.png"></li>
                <li><img src="/static/images/slide04.png"></li>
            </ul>
            <div class="prev"></div>
            <div class="next"></div>
            <ul class="points"></ul>
        </div>
        <div class="adv fl">
            <a href="#"><img src="/static/images/adv01.png"></a>
            <a href="#"><img src="/static/images/adv02.png"></a>
        </div>
    </div>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <div class="list_model" id="LAY_CarBrandList">

    </div>
    <script type="text/javascript" src="/static/js/slideshow.js"></script>
    <script type="text/javascript">
        BCSlideshow('focuspic');
        var oFruit = document.getElementById('fruit_more');
        var oShownum = document.getElementById('show_count');

        var hasorder = localStorage.getItem('order_finish');

        if(hasorder)
        {
            oShownum.innerHTML = '2';
        }

        oFruit.onclick = function(){
            window.location.href = 'list.html';
        }
    </script>
    <script>
        $('#searchButton').click(function() {
            var searchText = $('#searchInput').val(); // 获取搜索框中的值
            var searchUrl = '/page/car/list?search=' + encodeURIComponent(searchText); // 构建带有搜索关键字的URL
            window.location.href = searchUrl; // 跳转到另一个页面
        });
        $.post(
            '/brand?method=selectByBrand',
            function (result) {
                if (result.code == 0) {
                    $('#LAY_BrandList').empty();
                    $(result.data).each(function () {
                        var html = '';
                        html+='<li><a href="#model'+this.brandId+'" id="'+this.brandId+'">'+this.brandName+'</a></li>'
                        $('#LAY_BrandList').append(html);
                    })
                }
            },
            'json'
        );
        $.post(
            '/brand?method=selectByBrand',
            function (result) {
                if (result.code == 0) {
                    $('#LAY_CarBrandList').empty();
                    $(result.data).each(function (index, brand) {
                        var html = '';
                        html += '<div class="list_title clearfix">';
                        html += ' <h3 class="fl" id="model' + brand.brandId + '">' + brand.brandName + '</h3>';
                        html += ' <a href="page/list?brandId=' + brand.brandId + '" class="goods_more fr" id="fruit_more">查看更多 ></a>';
                        html += '</div>';

                        html += '<div class="goods_con clearfix">';
                        html += '    <div class="goods_banner fl"><img src="/pic/' + brand.brandImage + '"></div>';
                        html += '    <ul class="goods_list fl" id="LAY_CarList' + brand.brandId + '">';
                        html += '    </ul>';
                        html += '</div>';
                        $('#LAY_CarBrandList').append(html);

                        $.post(
                            '/car?method=selectByBrandCar',
                            { 'brandId': brand.brandId },
                            function (carResult) {
                                if (carResult.code == 0) {
                                    var carListHtml = '';
                                    $(carResult.data.slice(0, 4)).each(function () {
                                        carListHtml += '<li>';
                                        carListHtml += '    <h4><a href="/page/detail?carId=' + this.id + '&brandId=' + this.brandId + '">' + this.model + '</a></h4>';
                                        carListHtml += '    <a href="/page/detail?carId=' + this.id + '&brandId=' + this.brandId + '"><img src="/pic/' + this.image + '"></a>';
                                        carListHtml += '    <div class="prize">¥ ' + this.rentalPrice + '</div>';
                                        carListHtml += '</li>';
                                    });
                                    $('#LAY_CarList' + brand.brandId).html(carListHtml);
                                }
                            },
                            'json'
                        );
                    });
                }
            },
            'json'
        );
        // function logout() {
        //     layer.confirm(
        //         '您确认要退出么',
        //         {icon:3},
        //         function() {
        //             location.href = '/user?method=logout'
        //         }
        //     );
        // }
        function logout() {
            layer.confirm(
                '您确认要退出么',
                {icon:3},
                function() {
                    $.post(
                        '/user?method=logout',
                        function (result) {
                            if (result.code == 0) {
                                mylayer.okUrl(result.msg, '/page/login');
                            }
                        },
                        'json'
                    );
                    // location.href = '/admin?method=logout'
                }
            );
        }
    </script>
</body>
</html>